<#--生成业务逻辑层接口实现类-->
<#include "hihsoft_agreement.include">
<#assign className = table.className>   
<#assign tableName = table.sqlName>   
<#assign idColumn = table.idColumn ?lower_case>
<#assign classNameUpper=table.className?upper_case>
<#assign classNameLower = className?uncap_first> 
package ${basepackage}.${subpackage}.service.impl;
import java.util.List;
import java.util.Map;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.stereotype.Service;

import com.hihsoft.baseclass.service.impl.BaseServiceImpl;
import com.hihframework.exception.ServiceException;

import ${basepackage}.${subpackage}.service.*;
import ${basepackage}.${subpackage}.model.*;
<#include "java_copyright.include">
@Service(value ="${classNameLower}Service")
public class ${className}ServiceImpl extends BaseServiceImpl implements ${className}Service{
	/************查询所有的${classNameUpper}******************/
	private static final String ALL${classNameUpper}_HQL=" from ${className}";
	
	/************通过主键查询${classNameUpper}******************/
	private static final String ${classNameUpper}ById_HQL=" from ${className} ${classNameLower} where ${classNameLower}.${idColumn}=?";
	
	/************通过不同的条件组合，利用Hibernate HQL查询${classNameUpper}******************/
	private static final StringBuffer QUERY_${classNameUpper}_HQL = new StringBuffer(" from ${className} ${classNameLower} where 1=1");
	
	/************通过不同的条件组合，利用JDBC SQL查询${classNameUpper}******************/
	private static final StringBuffer QUERY_${classNameUpper}_SQL = new StringBuffer("select * from ${tableName} t where 1=1");

	/**
	 * 新增、修改${className}信息
	 * 
	 * @param ${classNameLower}
	 * @throws DataAccessException
	 */
	public void saveOrUpdate${className}(${className} ${classNameLower}) throws ServiceException {
		baseDAO.saveOrUpdateVO(${classNameLower});
	}

	/**
	 * 删除${className}信息
	 * 
	 * @param id
	 * @throws DataAccessException
	 */
	  public  void delete${className}(String id) throws ServiceException{
		  ${className} ${classNameLower}=this.get${className}ById(id);
		  baseDAO.deleteVO(${classNameLower});
	  }


	 /**
		 * 通过HQL构造查询条件来查询符合条件的${className}信息
		 * 
		 * @param hql
		 * @return List
		 * @throws DataAccessException
		 */
	  public List get${className}ByHQL(String hql) throws ServiceException{
		  return baseDAO.getValueObjectsByHQL(hql);
		  
	  }
		 /**
		 * 查询所有的${className}信息
		 * 
		 * @param hql
		 * @return List
		 * @throws DataAccessException
		 */
	  public List getAll${className}() throws ServiceException{
		  return  baseDAO.getValueObjectsByHQL(ALL${classNameUpper}_HQL);
	  }

	 /**
		 * 根据主键查询${className}信息明细
		 * 
		 * @param id
		 * @throws DataAccessException
		 */
	  public ${className} get${className}ById(String id) throws ServiceException{
		  ${className} ${classNameLower}=null;
		  List list=baseDAO.getValueObjectsByHQL(${classNameUpper}ById_HQL,new Object[]{id});
		  if(!list.isEmpty()&&list.size()>0){
			  ${classNameLower}=(${className})list.get(0);
		  }
		 return ${classNameLower};
	  }
	 /**
		 * 把查询条件构造成数组来查询${className}信息
		 * 
		 * @param Object[]
		 *            object
		 * @return List
		 * @throws DataAccessException
		 */
	  public List get${className}ByArray(Object[] filter) throws ServiceException{
		  return baseDAO.getValueObjectsByHQL(QUERY_${classNameUpper}_HQL.toString(),filter);
	  }
	  /**
		 * 取得分页总数
		 * 
		 * @param hql
		 * @param object
		 * @return
		 * @throws DataAccessException
		 */

	    public int get${className}DataTotalNum(Object[] filter)
	            throws ServiceException{
	    	return baseDAO.getDataTotalNum(QUERY_${classNameUpper}_HQL.toString(),filter);
	    }
	    
	    /**
		 * 把查询条件构造成数组来查询${className}信息
		 * 
		 * @param Map
		 *            filter
		 * @return List
		 * @throws DataAccessException
		 */
	  public List get${className}ByMap(Map filter) throws ServiceException{
		  return baseDAO.getPageDataByHQL(QUERY_${classNameUpper}_HQL.toString(),filter);
	  }

	    
      /**
	    * 分页查询
	    * 
	    * @param hql
	    * @param object
	    * @param page_size
	    * @param pageNo
	    * @return
	    * @throws DataAccessException
	 */

     public List get${className}PageDataByArray(Object[] filter, int page_size,
	                                 int pageNo) throws ServiceException{
	  return baseDAO.getPageDataByHQL(QUERY_${classNameUpper}_HQL.toString(),filter,page_size,pageNo);
}

	    
	    /**
		 * 分页查询。
		 * 
		 * @param hql
		 * @param obj：MAP条件构造
		 * @param page_size
		 * @param pageNo
		 * @return
		 * @throws DataAccessException
		 */
	    public List get${className}PageDataByMap(Map filter, int page_size, int pageNo)
	            throws ServiceException{
	    	 String id = (String) filter.get("id");
	    	return baseDAO.getPageDataByHQL(QUERY_${classNameUpper}_HQL.toString(),filter,page_size,pageNo);
	    }

	    /**
		 * 利用SQL数组条件来查询记录
		 * 
		 * @param sql
		 * @param object
		 * @return
		 * @throws DataAccessException
		 */
	    public List get${className}ValueObjectWithSQLByArray(Object[] filter) throws ServiceException{
	    	return baseDAO.getValueObjectBySQL(QUERY_${classNameUpper}_SQL.toString(),filter);
	    }

	    
		/**
		 * 通过配置SQL来执行查询带多个参数的情况 包括SQL语句、存储过程等
		 * 
		 * @param queryName
		 * @param object
		 * @return
		 * @throws DataAccessException
		 */
		public List get${className}ValueObjectByNameQuery(String queryName,Object[] filter)throws ServiceException{
			return baseDAO.getValueObjectByNameQuery(queryName,filter);
		}
		/**
		 * 动态构造HQL参数
		 * @param detachedCriteria
		 * @return
		 * @throws ServiceException
		 */
		public List get${className}ValueObjectByDetachedCriteria(
				DetachedCriteria detachedCriteria) throws ServiceException{
			return baseDAO.getValueObjectByDetachedCriteria(detachedCriteria);
		}

		/**
		 * 动态构造HQL参数
		 * @param detachedCriteria
		 * @return
		 * @throws ServiceException
		 */
		public List get${className}ValueObjectByDetachedCriterias(
				DetachedCriteria detachedCriteria, int arg1, int arg2)
				throws ServiceException{
			return baseDAO.getValueObjectByDetachedCriterias(detachedCriteria, arg1, arg2);
		}


}
